package com.baizhi.service.impl;

import com.baizhi.dao.CmfzArticleDao;
import com.baizhi.dao.CmfzBannerDao;
import com.baizhi.entity.CmfzArticle;
import com.baizhi.entity.CmfzBanner;
import com.baizhi.service.ArticleService;
import com.baizhi.service.BannerService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ArticleServiceImpl implements ArticleService {

    @Resource
    private CmfzArticleDao cmfzArticleDao;


    @Override
    public Page<CmfzArticle> selectAll(Integer page, Integer limit) {
        //1.创建一个分页对象 封装分页数据
        Page<CmfzArticle> articlePage = new Page<>(page, limit);
        //2.使用分页查询的方法
        Page<CmfzArticle> cmfzBannerPage = cmfzArticleDao.selectPage(articlePage, null);

        return cmfzBannerPage;
    }

    @Override
    public CmfzArticle showOne(Integer id) {

        return cmfzArticleDao.selectById(id);
    }

    @Override
    public void insert(CmfzArticle cmfzArticle) {
        try {
            cmfzArticleDao.insert(cmfzArticle);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void delete(Integer id) {
        try {
            cmfzArticleDao.deleteById(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void update(CmfzArticle cmfzArticle) {
        try {
            cmfzArticleDao.update(cmfzArticle,null);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    @Override
    public void deleteAll(List<CmfzArticle> ids) {
        try {
            cmfzArticleDao.deleteBatchIds(ids);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
